package com.hundsun.yr.universal.p2p.presenter.impl;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;

import com.hundsun.mobile.zwgt.R;
import com.hundsun.yr.universal.library.data.HSSharedPreferences;
import com.hundsun.yr.universal.library.eventbus.EventCenter;
import com.hundsun.yr.universal.library.netstatus.NetUtils;
import com.hundsun.yr.universal.library.widget.HSToast;
import com.hundsun.yr.universal.p2p.bean.AdSlideBeen;
import com.hundsun.yr.universal.p2p.bean.AssetInfoBean;
import com.hundsun.yr.universal.p2p.bean.AutoBidInfoBean;
import com.hundsun.yr.universal.p2p.bean.BankAccountBeen;
import com.hundsun.yr.universal.p2p.bean.ManeBean;
import com.hundsun.yr.universal.p2p.bean.MineInvestProtocolBean;
import com.hundsun.yr.universal.p2p.bean.MixrepayPlanBean;
import com.hundsun.yr.universal.p2p.bean.PrepayPlanBeen;
import com.hundsun.yr.universal.p2p.bean.RepayPlanBeen;
import com.hundsun.yr.universal.p2p.bean.UserInfo;
import com.hundsun.yr.universal.p2p.config.Config;
import com.hundsun.yr.universal.p2p.config.Constants;
import com.hundsun.yr.universal.p2p.config.TaskConstants;
import com.hundsun.yr.universal.p2p.interactor.base.BaseItemViewInteractor;
import com.hundsun.yr.universal.p2p.interactor.base.RequestInteractor;
import com.hundsun.yr.universal.p2p.interactor.impl.StringRequestGetInteractorImpl;
import com.hundsun.yr.universal.p2p.interactor.impl.StringRequestInteractorImpl;
import com.hundsun.yr.universal.p2p.listener.BaseMultiLoadedListener;
import com.hundsun.yr.universal.p2p.presenter.base.RequestPresenter;
import com.hundsun.yr.universal.p2p.utils.AndroidDes3Util;
import com.hundsun.yr.universal.p2p.utils.CommTool;
import com.hundsun.yr.universal.p2p.utils.GsonTool;
import com.hundsun.yr.universal.p2p.utils.Logs;
import com.hundsun.yr.universal.p2p.view.base.BaseItemView;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import de.greenrobot.event.EventBus;


/**
 * @version V1.0
 * @Title: ItemViewPresenterImpl.java
 * @Description: TODO(用一句话描述该文件做什么) 项目详情的p层
 * @date 2016-1-11 下午2:55:30
 * @author:hejun.shen
 * @email:shenhj15971@hundsun.com
 * @replace author:
 * @replace date:
 */
public class ItemViewPresenterImpl implements RequestPresenter, BaseMultiLoadedListener<String> {

    private Context mContext = null;
    private BaseItemView mView = null;
    private BaseItemViewInteractor mInteractor = null;
    private RequestInteractor mRequestInteractor = null;
    private RequestInteractor mRequestInteractor2 = null;
    private HSSharedPreferences hsSharedPreferences = null;
    private HSSharedPreferences mConfigSP = null;

    public ItemViewPresenterImpl(Context context, BaseItemView view, BaseItemViewInteractor baseInteractor) {
        // TODO Auto-generated constructor stub
        if (null == view) {
            throw new IllegalArgumentException("Constructor's parameters must not be Null");
        }
        this.mContext = context;
        this.mView = view;
        this.mInteractor = baseInteractor;
        this.mRequestInteractor = new StringRequestInteractorImpl(this);
        this.mRequestInteractor2 = new StringRequestGetInteractorImpl(this);
        hsSharedPreferences = new HSSharedPreferences(context, Config.SPPath.file_userLoginedInfo);
        mConfigSP = new HSSharedPreferences(mContext, Config.SPPath.file_configInfo);
    }

    @Override
    public void initialized() {
        // TODO Auto-generated method stub
        mView.setAdapter(mInteractor.getListItemData(mContext));

    }

    /**
     * 网络请求成功之后的回调
     *
     * @param task_name
     * @param event_tag
     * @param data
     */
    @Override
    public void onSuccess(String task_name, int event_tag, String data) {
        Logs.e("data: 77777" + task_name +  data);
        // TODO Auto-generated method stub
        try {
            AdSlideBeen adSlideBeen = (AdSlideBeen) GsonTool.getInstanceByJson(AdSlideBeen.class, data);
            if (adSlideBeen.code.equals(Constants.REQUESTCODE_100600)){
                hsSharedPreferences.putBoolean(UserInfo.ISLOGIN, false);
                EventBus.getDefault().post(new EventCenter(Constants.EVENT_DATA_LOGIN_EXPIRED));
            }
            switch (task_name) {
                case TaskConstants.TASK_BANK_ACCOUNT:
                    //查询托管账户信息
                    switch (adSlideBeen.code) {
                        case Constants.REQUESTCODE_000000:
                            //请求网络成功
                            try {
                                String decode = AndroidDes3Util.decode(adSlideBeen.data, hsSharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
                                String[] split = decode.split("\\n");

                                //数据解析成功，通知v层
                                BankAccountBeen bankAccountBeen = (BankAccountBeen) GsonTool.getInstanceByJson(BankAccountBeen.class, split[1]);
                                Logs.e("bankAccountBeen:77777 " + split[1]);
                                mView.initializeViews(task_name, bankAccountBeen);
                            } catch (Exception e) {
//								new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
                                e.printStackTrace();
                            }

                            mConfigSP.putBoolean(UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS, true);
                            break;

                        case Constants.REQUESTCODE_100500:
                            new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_overdue)).show();
                            mConfigSP.putBoolean(UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS, false);
                            break;
                        case Constants.REQUESTCODE_200401:
//							new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
//							EventBus.getDefault().post(new EventCenter(Constants.EVENT_REFRESH_INFO_DATA));//通知某些页面进行数据刷新
                            mConfigSP.putBoolean(UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS, true);
                            break;
                        case Constants.REQUESTCODE_100020:
                            //Header值为空--不做任何提示
                            mConfigSP.putBoolean(UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS, true);
                            break;
                        case Constants.REQUESTCODE_100600:
                            new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
                            hsSharedPreferences.putBoolean(UserInfo.ISLOGIN, false);
                            CommTool.goToLogin(mContext);
                            mConfigSP.putBoolean(UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS, false);
                            EventBus.getDefault().post(new EventCenter(Constants.EVENT_DATA_LOGIN_EXPIRED2));
                            break;
                        case Constants.REQUESTCODE_100010:
                            mConfigSP.putBoolean(UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS, false);
                            break;
                        default:
                            new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
                            mConfigSP.putBoolean(UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS, false);
                            break;
                    }
                    break;
                case TaskConstants.TASK_REFRESH:
                    //查询托管账户信息
                    switch (adSlideBeen.code) {
                        case Constants.REQUESTCODE_000000:
                            //请求网络成功
                            try {
                                String decode = AndroidDes3Util.decode(adSlideBeen.data, hsSharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
                                String[] split = decode.split("\\n");

                                //数据解析成功，通知v层
                                BankAccountBeen bankAccountBeen = (BankAccountBeen) GsonTool.getInstanceByJson(BankAccountBeen.class, split[1]);
                                Logs.e("bankAccountBeen:77777 " + split[1]);
                                mView.initializeViews(task_name, bankAccountBeen);
                            } catch (Exception e) {
//								new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
                                e.printStackTrace();
                            }

                            mConfigSP.putBoolean(UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS, true);
                            break;

                        case Constants.REQUESTCODE_100500:
                            new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_overdue)).show();
                            mConfigSP.putBoolean(UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS, false);
                            break;
                        case Constants.REQUESTCODE_200401:
//							new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
//							EventBus.getDefault().post(new EventCenter(Constants.EVENT_REFRESH_INFO_DATA));//通知某些页面进行数据刷新
                            mConfigSP.putBoolean(UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS, true);
                            break;
                        case Constants.REQUESTCODE_100020:
                            //Header值为空--不做任何提示
                            mConfigSP.putBoolean(UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS, true);
                            break;
                        case Constants.REQUESTCODE_100600:
                            new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
                            hsSharedPreferences.putBoolean(UserInfo.ISLOGIN, false);
                            CommTool.goToLogin(mContext);
                            mConfigSP.putBoolean(UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS, false);
                            EventBus.getDefault().post(new EventCenter(Constants.EVENT_DATA_LOGIN_EXPIRED2));
                            break;
                        case Constants.REQUESTCODE_100010:
                            mConfigSP.putBoolean(UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS, false);
                            break;
                        default:
                            new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
                            mConfigSP.putBoolean(UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS, false);
                            break;
                    }
                    break;
                case TaskConstants.TASK_REPAYPLAN: //OK
                    //还款计划
                    switch (adSlideBeen.code) {
                        case Constants.REQUESTCODE_000000:
                            //通知V层
                            try {
                                String decode = AndroidDes3Util.decode(adSlideBeen.data, hsSharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
                                String[] split = decode.split("\\n");
                                ArrayList<RepayPlanBeen> repayPlanBeens = GsonTool.jsonToArrayList(split[1], RepayPlanBeen.class);
                                //数据解析成功，通知v层
                                mView.initializeViews(task_name, repayPlanBeens);
                            } catch (Exception e) {
                                new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
                                e.printStackTrace();
                            }
                            break;
                        case Constants.REQUESTCODE_100500:
                            new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_overdue)).show();
                            break;
                        case Constants.REQUESTCODE_100020:
                            //Header值为空--不做任何提示
                            break;
                        case Constants.REQUESTCODE_100010:
                            break;
                        default:
                            new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
                            break;
                    }
                    break;
                case TaskConstants.TASK_REPAY://还款 OK
                    switch (adSlideBeen.code) {
                        case Constants.REQUESTCODE_000000:
                            //通知V层
                            try {
                                String decode = AndroidDes3Util.decode(adSlideBeen.data, hsSharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
                                String[] split = decode.split("\\n");
                                mView.initializeViews(TaskConstants.TASK_REPAY, split[1]);
                            } catch (Exception e) {
                                new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
                                e.printStackTrace();
                            }
                            break;
                        case Constants.REQUESTCODE_100500:
                            new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_overdue)).show();
                            break;
                        case Constants.REQUESTCODE_100020:
                            //Header值为空--不做任何提示
                            break;
                        case Constants.REQUESTCODE_100010:
                            break;
                        default:
                            new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
                            break;
                    }
                    break;

                case TaskConstants.TASK_APPLYCANCEL://借款撤销 OK
                    switch (adSlideBeen.code) {
                        case Constants.REQUESTCODE_000000:
                            //请求成功，对数据进行解密
                            try {
                                String decode = AndroidDes3Util.decode(adSlideBeen.data, hsSharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), (Date.parse(adSlideBeen.timestamp) + "").substring(0, 8));
                                String[] split = decode.split("\\n");
                                mView.initializeViews(TaskConstants.TASK_APPLYCANCEL, split[1]);
                            } catch (Exception e) {
                                new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
                                e.printStackTrace();
                            }
                            break;
                        case Constants.REQUESTCODE_100500:
                            new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_overdue)).show();
                            break;
                        case Constants.REQUESTCODE_100020:
                            //Header值为空--不做任何提示
                            break;
                        case Constants.REQUESTCODE_100010:
                            break;
                        default:
                            new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
                            break;

                    }
                    break;
                case TaskConstants.TASK_ASSETINFO:
                    //查询托管账户信息
                    switch (adSlideBeen.code) {
                        case Constants.REQUESTCODE_000000:
                            //请求网络成功
                            try {
                                String decode = AndroidDes3Util.decode(adSlideBeen.data, hsSharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
                                String[] split = decode.split("\\n");
                                AssetInfoBean assetInfoBean = (AssetInfoBean) GsonTool.getInstanceByJson(AssetInfoBean.class, split[1]);
                                //数据解析成功，通知v层
                                Logs.e("assetinfobean:77777 " + split[1]);
                                mView.initializeViews(TaskConstants.TASK_ASSETINFO, assetInfoBean);
                            } catch (Exception e) {
                                mView.initializeError(task_name, "");
                                new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
                                e.printStackTrace();
                            }
                            break;
                        case Constants.REQUESTCODE_100500:
                            mView.initializeError(task_name, "");
                            break;
                        case Constants.REQUESTCODE_100020:
                            mView.initializeError(task_name, "");
                            break;
                        case Constants.REQUESTCODE_100010:
                            mView.initializeError(task_name, "");
                            break;
                        default:
                            mView.initializeError(task_name, "");
//                            new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
                            break;
                    }
                    break;

                case TaskConstants.TASK_INVESTPROTOCOL:
                    switch (adSlideBeen.code) {
                        case Constants.REQUESTCODE_000000:
                            //请求网络成功
                            try {
                                String decode = AndroidDes3Util.decode(adSlideBeen.data, hsSharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
                                String[] split = decode.split("\\n");
                                //数据解析成功，通知v层
                                MineInvestProtocolBean mineInvestProtocolBean = (MineInvestProtocolBean) GsonTool.getInstanceByJson(MineInvestProtocolBean.class, split[1]);
                                Log.e("Datafda",split[1]);
                                Log.e("Datafdadfdf",adSlideBeen.toString());

                                if(TextUtils.isEmpty(adSlideBeen.getUrl())){
                                    mView.initializeViews(TaskConstants.TASK_INVESTPROHTML, mineInvestProtocolBean);
                                }else {
                                    mView.initializeViews(TaskConstants.TASK_INVESTPROTOCOL, adSlideBeen);
                                }
                            } catch (Exception e) {
                                new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
                                e.printStackTrace();
                            }
                            break;
                        case Constants.REQUESTCODE_100020:
                            //Header值为空--不做任何提示
                            break;
                        case Constants.REQUESTCODE_100010:
                            break;
                        default:
                            break;
                    }
                    break;

                case TaskConstants.TASK_AUTOBIDINFO://查询投标情况
                    switch (adSlideBeen.code) {
                        case Constants.REQUESTCODE_000000:
                            String decode = AndroidDes3Util.decode(adSlideBeen.data, hsSharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
                            String[] split = decode.split("\\n");
                            AutoBidInfoBean autoBidInfoBean = (AutoBidInfoBean) GsonTool.getInstanceByJson(AutoBidInfoBean.class, split[1]);
                            mView.initializeViews(TaskConstants.TASK_AUTOBIDINFO, autoBidInfoBean);
                            break;
                        default:
                            new HSToast(mContext).showCustomToast(adSlideBeen.msg);
                            break;
                    }
                    break;

                //提前还款计划
                case TaskConstants.TASK_PREPAYPLAN://提前还款计划
                    switch (adSlideBeen.code) {
                        case Constants.REQUESTCODE_000000:
                            //通知V层
                            try {
                                String decode = AndroidDes3Util.decode(adSlideBeen.data, hsSharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
                                String[] split = decode.split("\\n");
                                PrepayPlanBeen prepayPlanBeen = (PrepayPlanBeen) GsonTool.getInstanceByJson(PrepayPlanBeen.class, split[1]);
                                mView.initializeViews(TaskConstants.TASK_PREPAYPLAN, prepayPlanBeen);
                            } catch (Exception e) {
                                new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
                                e.printStackTrace();
                            }
                            break;
                        case Constants.REQUESTCODE_100500:
                            new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_overdue)).show();
                            break;
                        case Constants.REQUESTCODE_100020:
                            break;
                        case Constants.REQUESTCODE_100010:
                            break;
                        default:
                            new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
                            break;
                    }
                    break;

                case TaskConstants.TASK_PREPAY://提前还款 OK
                    switch (adSlideBeen.code) {
                        case Constants.REQUESTCODE_000000:
                            //通知V层
                            try {
                                String decode = AndroidDes3Util.decode(adSlideBeen.data, hsSharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
                                String[] split = decode.split("\\n");
                                mView.initializeViews(TaskConstants.TASK_PREPAY, split[1]);
                            } catch (Exception e) {
                                new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
                                e.printStackTrace();
                            }
                            break;
                        case Constants.REQUESTCODE_100500:
                            new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_overdue)).show();
                            break;
                        case Constants.REQUESTCODE_100020:
                            break;
                        case Constants.REQUESTCODE_100010:
                            break;
                        default:
                            new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
                            break;
                    }
                    break;

                case TaskConstants.TASK_NEWREPAY://综合还款
                    Logs.e("TASK_NEWREPAY:77777 " + adSlideBeen);
                    switch (adSlideBeen.code) {

                        case Constants.REQUESTCODE_000000:
                            //通知V层
                            try {
                                String decode = AndroidDes3Util.decode(adSlideBeen.data, hsSharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
                                String[] split = decode.split("\\n");
                                mView.initializeViews(TaskConstants.TASK_NEWREPAY, split[1]);
                            } catch (Exception e) {
                                new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
                                e.printStackTrace();
                            }
                            break;
                        case Constants.REQUESTCODE_100500:
                            break;
                        case Constants.REQUESTCODE_100020:
                            break;
                        case Constants.REQUESTCODE_100010:
                            break;
                        case Constants.REQUESTCODE_000001:
                            mView.initializeViews(TaskConstants.TASK_RETURN_MONEY, adSlideBeen);
                            break;
                        case Constants.REQUESTCODE_000002:
                            mView.initializeViews(TaskConstants.TASK_RETURN_MONEY, adSlideBeen);
                            break;
                        case Constants.REQUESTCODE_000003:
                            mView.initializeViews(TaskConstants.TASK_RETURN_MONEY, adSlideBeen);
                            break;
                        case Constants.REQUESTCODE_000004:
                            mView.initializeViews(TaskConstants.TASK_RETURN_MONEY, adSlideBeen);
                            break;
                        case Constants.REQUESTCODE_000005:
                            mView.initializeViews(TaskConstants.TASK_CHARGE_CHARGE, adSlideBeen);
                            break;
                        default:
                            new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
                            break;
                    }
                    break;
                    //设置交易密码
                case TaskConstants.TASK_SETBANKPWD://设置修改交易密码
                    Log.e("SETPSD",adSlideBeen.toString());
                    switch (adSlideBeen.code) {
                        case Constants.REQUESTCODE_000000:
                            try {
                                String decode3 = AndroidDes3Util.decode(adSlideBeen.data, hsSharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
                                String[] split3 = decode3.split("\\n");
                                ManeBean mUpdatePayPwdBeen = (ManeBean) GsonTool.getInstanceByJson(ManeBean.class, split3[1]);
                                mView.initializeViews(TaskConstants.TASK_SETBANKPWD, mUpdatePayPwdBeen.getData());
                            } catch (Exception e) {
                                e.printStackTrace();
                                new HSToast(mContext).showToast(mContext.getString(R.string.date_error) + e.toString());
                            }
                            break;
                        case Constants.REQUESTCODE_100500:
                            //验签错误重新登录
                            new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_overdue)).show();
                            break;
                        case Constants.REQUESTCODE_100020:
                            break;
                        case Constants.REQUESTCODE_100010:
                            break;
                        default:
                            new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
                            break;

                    }
                    break;

                case TaskConstants.TASK_MIXREPAYPLAN://最新还款计划
                    switch (adSlideBeen.code) {
                        case Constants.REQUESTCODE_000000:
                            //通知V层
                            try {
                                String decode = AndroidDes3Util.decode(adSlideBeen.data, hsSharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
                                String[] split = decode.split("\\n");
                                MixrepayPlanBean prepayPlanBeen = (MixrepayPlanBean) GsonTool.getInstanceByJson(MixrepayPlanBean.class, split[1]);
                                Logs.e("TASK_MIXREPAYPLAN:77777 " + split[1]);
                                mView.initializeViews(TaskConstants.TASK_MIXREPAYPLAN, prepayPlanBeen);
                            } catch (Exception e) {
                                new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
                                e.printStackTrace();
                            }
                            break;


                        case Constants.REQUESTCODE_100500:
                            new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_overdue)).show();
                            break;
                        case Constants.REQUESTCODE_100020:
                            break;
                        case Constants.REQUESTCODE_100010:
                            break;
                        default:
                            new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
                            break;
                    }
                    break;
                /**
                 * 提现操作
                 */
                case TaskConstants.TASK_NEW_TRADE:
                    Logs.e("TASK:55555 " + adSlideBeen);
                   switch (adSlideBeen.getCode()){
                       //允许跳转至借款详情页面,
                       case Constants.REQUESTCODE_000000:
                           //判断是出借人还是借款人
                           String decode = AndroidDes3Util.decode(adSlideBeen.data, hsSharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
                           String[] split = decode.split("\\n");
                           Logs.e("TASK:55555 " + split[1]);
                           MixrepayPlanBean prepayPlanBeen = (MixrepayPlanBean) GsonTool.getInstanceByJson(MixrepayPlanBean.class, split[1]);
                           mView.initializeViews(TaskConstants.TASK_IDCARD, prepayPlanBeen);
                           break;
                       //未实名
                       case Constants.REQUESTCODE_000001:
                           mView.initializeViews(TaskConstants.TASK_NEW_TRADE, adSlideBeen);
                           break;
                       //未设置密码
                       case Constants.REQUESTCODE_000002:
                           mView.initializeViews(TaskConstants.TASK_NEW_TRADE, adSlideBeen);
                           break;
                           //未绑卡，跳转至绑卡
                       case Constants.REQUESTCODE_000003:
                           mView.initializeViews(TaskConstants.TASK_NEW_TRADE, adSlideBeen);
                           break;
                       case Constants.REQUESTCODE_000004:
                           mView.initializeViews(TaskConstants.TASK_NEW_TRADE, adSlideBeen);
                           break;
                   }
                    break;
            }
        } catch (Exception e) {
            new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
            e.printStackTrace();
            mView.closeProgress();
        }
        mView.closeProgress();
    }


    @Override
    public void onException(String task_name, String msg) {
        // TODO Auto-generated method stub
        mView.closeProgress();
        new HSToast(mContext).showToast(msg);
        mView.initializeError(task_name, "");
    }


    @Override
    public void loadingData(final String task_name, final String url, final int event_tag,
                            final HashMap<String, String> params, final boolean isSwipeRefresh) {
        // TODO Auto-generated method stub
        if (NetUtils.isNetworkConnected(mContext)) {
            if (isSwipeRefresh) {
                mView.showProgress("");
            }
            mRequestInteractor2.getRequestData(task_name, url, event_tag, params);
        } else {
            mView.closeProgress();
            new HSToast(mContext).showToast(R.string.common_no_network);
            mView.initializeError(task_name, "");
        }
    }

    /**
     * 详情页面的请求
     *
     * @param task_name
     * @param url
     * @param event_tag
     * @param params
     * @param header
     * @param isSwipeRefresh
     */
    @Override
    public void loadingData(String task_name, String url, int event_tag, HashMap<String, String> params, HashMap<String, String> header, boolean isSwipeRefresh) {
        //根据task_name进行网络请求
        if (NetUtils.isNetworkConnected(mContext)) {
            if (isSwipeRefresh) {
                mView.showProgress("");
            }
            mRequestInteractor2.getRequestData(task_name, url, event_tag, params, header);
        } else {
            mView.closeProgress();
            new HSToast(mContext).showToast(R.string.common_no_network);
            mView.initializeError(task_name, "");
        }
    }

    @Override
    public void loadingData(String task_name, String url, int event_tag, JSONObject params, HashMap<String, String> header, boolean isSwipeRefresh) {
        if (NetUtils.isNetworkConnected(mContext)) {
            if (isSwipeRefresh) {
                mView.showProgress("");
            }
            mRequestInteractor.getRequestData(task_name, url, event_tag, params, header);
        } else {
            mView.closeProgress();
            new HSToast(mContext).showToast(R.string.common_no_network);
            mView.initializeError(task_name, "");
        }
    }

}
